package com.woniuxy.carlife.carlifenewcomplaintsweb.controller;


import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.dto.StoreMessageDto;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.param.StoreMessageParam;
import com.woniuxy.carlife.carlifenewcomplaintsweb.service.StoreMessageService;
import com.woniuxy.carlife.carlifenewcomplaintsweb.utils.StatusMessageEnum;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yp
 * @ClassName:StoreMessageController
 * @Description:门店消息
 * @date 2021/4/7 2:32
 **/
@RestController
@Slf4j
@Api(tags = "门店消息管理接口")
@RequestMapping("/storeMessage")
public class StoreMessageController {
    @Resource
    private StoreMessageService  storeMessageService;

    /*
     * 功能描述〈添加门店消息〉
     * @author:yp
     * @param:UserMessageParam
     * @return:
     * @Date 2021/4/12 9:58
     * @throws
     */
    @PostMapping("/platformmanage/addStoreMessage")
    @ApiOperation(value = "添加门店消息信息",notes = "<span style='color:red;'>添加门店消息信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "添加成功"),
            @ApiResponse(code=20001,message = "添加失败")
    })
    public Result addStoreMessage(@RequestBody @ApiParam StoreMessageParam storeMessageParam){
        if(storeMessageParam==null){
            return new Result(false,StatusCode.ERROR,"参数错误");
        }
        log.info("开始业务:添加门店消息");
        int num = storeMessageService.addStoreMessage(storeMessageParam);
        log.info("结束业务:添加门店消息");
        if (num==1){
            return new Result(true, StatusCode.OK, StatusMessageEnum.SAVE_SUCCESS.toString());
        }
        return new Result(false,StatusCode.ERROR,StatusMessageEnum.SAVE_FAIL.toString());
    }

    /*
     * 功能描述〈查询门店消息〉
     * @author:yp
     * @param:StoreMessageParam
     * @return:List<StoreMessageDto>
     * @Date 2021/4/12 14:05
     * @throws
     */
    @GetMapping("/merchantmanage/findStoreMessage")
    @ApiOperation(value = "查询门店消息信息",notes = "<span style='color:red;'>查询门店消息信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询成功"),
            @ApiResponse(code=20001,message = "查询失败")
    })

    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "storeId",value = "门店id",dataType = "int",paramType = "query",example = "1"),
    })

    public Result findStoreMessage(Integer storeId){
        if(storeId==null){
            return new Result(false,StatusCode.ERROR,"参数错误");
        }
        log.info("开始业务:查询门店消息");
        List<StoreMessageDto> list = storeMessageService.findStoreMessage(storeId);
        log.info("结束业务:查询门店消息");
        if (list.size()!=0){
            return new Result(true,StatusCode.OK,StatusMessageEnum.FIND_SUCCESS.toString(),list);
        }
        return new Result(false,StatusCode.ERROR,StatusMessageEnum.FIND_FAIL.toString());
    }

    /*
     * 功能描述〈修改门店消息状态〉
     * @author:yp
     * @param: StoreMessageParam
     * @return:
     * @Date 2021/4/12 14:08
     * @throws
     */
    @GetMapping("/merchantmanage/updateStoreMessage")
    @ApiOperation(value = "修改门店消息状态信息",notes = "<span style='color:red;'>修改门店消息状态信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "修改成功"),
            @ApiResponse(code=20001,message = "修改失败")
    })

    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "storeMessageId",value = "门店消息id",dataType = "int",paramType = "query",example = "1"),
    })
    public Result updateStoreMessage(Integer storeMessageId){
        if(storeMessageId==null){
            return new Result(false,StatusCode.ERROR,"参数错误");
        }
        log.info("开始业务:修改门店消息状态");
        int num =storeMessageService.updateStoreMessage(storeMessageId);
        log.info("结束业务:修改门店消息状态");
        if (num==1){
            return new Result(true,StatusCode.OK,StatusMessageEnum.UPDATE_SUCCESS.toString());
        }
        return new Result(false,StatusCode.ERROR,StatusMessageEnum.UPDATE_FAIL.toString());
    }

    /*
     * 功能描述〈删除门店消息〉
     * @author:yp
     * @param:StoreMessageParam
     * @return:
     * @Date 2021/4/12 14:10
     * @throws
     */
    @GetMapping("/merchantmanage/deleteStoreMessageParam")
    @ApiOperation(value = "删除门店消息信息",notes = "<span style='color:red;'>删除门店消息信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "删除成功"),
            @ApiResponse(code=20001,message = "删除失败")
    })

    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "storeMessageId",value = "门店消息id",dataType = "int",paramType = "query",example = "1"),
    })
    public Result deleteStoreMessageParam(Integer storeMessageId){
        if(storeMessageId==null){
            return new Result(false,StatusCode.ERROR,"参数错误");
        }
        log.info("开始业务:删除门店消息");
        int num = storeMessageService.deleteStoreMessageParam(storeMessageId);
        log.info("结束业务:删除门店消息");
        if (num==1){
            return new Result(true,StatusCode.OK,StatusMessageEnum.UPDATE_SUCCESS.toString());
        }
        return new Result(false,StatusCode.ERROR,StatusMessageEnum.UPDATE_FAIL.toString());
    }
}

